package com.jy.appmarket.utils;

import java.lang.reflect.Method;

import android.content.ContentResolver;
import android.content.ContentValues;
import android.content.Context;
import android.net.Uri;
import android.os.Build;
import android.util.Log;

public class InitUtil {

	private static final String TAG = InitUtil.class.getSimpleName();

	public static void OptimizeBootStartup(Context ctx) {
		if(Build.BRAND.equalsIgnoreCase("vivo") && "Funtouch".equalsIgnoreCase(getOSName())) {
			try {
				Uri CONTENT_URI = Uri.parse("content://com.iqoo.secure.provider.secureprovider/forbidbgstartappslist");
				ContentResolver cr = ctx.getContentResolver();
				cr.delete(CONTENT_URI, "pkgname=?", new String[] { ctx.getPackageName() });
			} catch (Exception e) {
			}
		}
		if(Build.BRAND.equalsIgnoreCase("lenovo")) {
			try {
				Uri CONTENT_URI = Uri.parse("content://com.lenovo.safecenter.autosetup/pkgname/update/" + ctx.getPackageName());
				ContentResolver cr = ctx.getContentResolver();
				ContentValues value = new ContentValues();
				value.put("state", true);
				value.put("stateBoot", 1);
				value.put("stateConn", 1);
				value.put("statePresent", 1);
				cr.update(CONTENT_URI, value, null, null);
				cr.notifyChange(CONTENT_URI, null);
			} catch (Exception e) {
			}
		}
	}

	private static String getOSName() {
		String name = "";
		try {
			Class<?> clz = Class.forName("android.os.Build");
			Method method = clz.getDeclaredMethod("getString", String.class);
			method.setAccessible(true);
			name = (String) method.invoke(null, "ro.vivo.os.name");
		} catch (Exception e) {
			Log.e(TAG, "getOsName failed");
		}
		return name;
	}

}
